<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/20
 * Time: 15:21
 */

namespace api\controllers;


use yii\db\Query;
use yii\filters\auth\HttpBearerAuth;
use yii\rest\Controller;

class Top10Controller extends Controller
{
    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
            'class' => HttpBearerAuth::className(),
        ];
        return $behaviors;
    }
    public function actionIndex()
    {
        $top10 = (new Query())
            ->from('post')
            ->select('author_id,count(id) as counts')
            ->groupBy('author_id')
            ->orderBy('counts desc')
            ->all();
        return $top10;
    }
}